var time = new Date().valueOf();
var 图集=new Array()
 图集[0]=images.read("/sdcard/脚本/图片/安装领取.jpg")
 图集[1]=images.read("/sdcard/脚本/图片/点击领取.jpg")
 图集[2]=images.read("/sdcard/脚本/图片/狠心放弃.jpg")
 图集[3]=images.read("/sdcard/脚本/图片/直接领取.jpg")
 图集[4]=images.read("/sdcard/脚本/图片/蓝水壶.jpg")
 图集[5]=images.read("/sdcard/脚本/图片/关闭兑奖.jpg")
 图集[6]=images.read("/sdcard/脚本/图片/继续种花.jpg")
 图集[7]=images.read("/sdcard/脚本/图片/开心收下.jpg")
 图集[8]=images.read("/sdcard/脚本/图片/去浇水.jpg")
 图集[9]=images.read("/sdcard/脚本/图片/立即领取.jpg")
  图集[10]=images.read("/sdcard/脚本/图片/金水壶.jpg")
  图集[11]=images.read("/sdcard/脚本/图片/知道了.jpg")
  图集[12]=images.read("/sdcard/脚本/图片/华农太忙.jpg")
var thread1 =threads.start(function () {

    while (true) {

        click("立即开始")


        sleep(500)
    }
});
if(!requestScreenCapture()){
    toast("请求截图失败");
    exit();
}
sleep(5000)
thread1.interrupt()
var img = captureScreen();
app.startActivity({
    action: "android.intent.action.VIEW",
    data: 'hiapp://com.huawei.appmarket?activityName=activityUri|webview.activity&params={"params":[{"name":"url","type":"String","value":"' + encodeURIComponent("https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46929&shareId=463783639952396032&shareTo=weixin&shareFrom=appmarket#/") + '"},{"name":"uri","type":"String","value":"external_webview"}]}&channelId=',
    packageName: "com.huawei.appmarket"
});
  
while (1) {
    
   
    //关闭签到框
    找色("#fffffd",[[-17,171,"#fb776a"],[-107,209,"#f9f1e6"],[21,214,"#f9f0e7"],[218,1069,"#7feee5"],[307,992,"#f42d26"]],"关闭签到框");
    click("邀请送花瓣");
    click("立即领取");
    let img = captureScreen();
    //关闭明日可领
    var p = images.findMultiColors(img, "#ffffff",[[-50,175,"#783000"],[171,192,"#773100"],[-178,925,"#a2a2a2"],[-10,917,"#a4a4a4"],[194,929,"#a0a0a0"],[-56,945,"#ffffff"],[-9,949,"#ffffff"],[30,949,"#ffffff"]]);
    if (p) {
        log("关闭明日可领");
        click(p.x, p.y)
        sleep(3000)
        break;
    }
   //开心收下
  找色("#fdb522",[[-2,-13,"#ffffff"],[0,14,"#feebc9"],[-53,-1,"#ffffff"],[82,-3,"#ffffff"],[47,-6,"#fdba25"],[38,7,"#fdb01e"],[1,-11,"#ffffff"]],"开心收下");
  


}
console.log("已完成邀请");

//点击采蜜
while (1) {
 //开心收下
 找色("#fdb522",[[-2,-13,"#ffffff"],[0,14,"#feebc9"],[-53,-1,"#ffffff"],[82,-3,"#ffffff"],[47,-6,"#fdba25"],[38,7,"#fdb01e"],[1,-11,"#ffffff"]],"开心收下");
 
    //关闭签到框
   找色("#fffffd",[[-17,171,"#fb776a"],[-107,209,"#f9f1e6"],[21,214,"#f9f0e7"],[218,1069,"#7feee5"],[307,992,"#f42d26"]],"关闭签到框");
   //点击小蜜蜂
   var img = captureScreen();
    var p = images.findMultiColors(img, "#fac60d", [[49, -46, "#e2e9f4"], [5, -86, "#e2e9f4"], [-25, -7, "#fac60d"], [-50, 46, "#ecaf09"], [-24, 2, "#fac60d"]]);
    if (p) {
        console.log("点击采蜜");
        sleep(1000)
        click(p.x, p.y);
        click(p.x, p.y);
        break
    }
    sleep(500)
}
console.log("已点击去采蜜");
while (1) {
    sleep(10);
    click("开始采蜜")
    click("拆水滴大礼包");
    click("继续免费挑战");
    //采蜜
    let img = captureScreen();
    var p = images.findMultiColors(img, "#ffd248", [[-40, 71, "#71960c"], [33, 59, "#688e09"], [103, 159, "#567c06"], [-104, 198, "#fec66d"]], {
        region: [452, 1700, 350, 230]
    });
    if (p) {
        
        click(871, 2251)
    }
    //杀虫
    p = images.findMultiColors(img, "#ffffff", [[40, -3, "#ffffff"], [28, 15, "#cd6c37"], [57, 15, "#ff9f49"], [162, 138, "#fec76f"], [-62, 152, "#fec66d"]], {
        region: [452, 1743, 350, 200]
    });
    if (p) {

        click(207, 2254)
    }
    if (text("明日再来").findOne(20)) {
        console.log("采蜜完成");
        back()
        break;
    }
}
console.log("已采蜜");

while (1) {
   
   var 去领取 = textContains("去领取").findOne(100)
    if (去领取) {
        sleep(1000)
        click("去领取")
    }
    var 去消费 = textContains("去领取").findOne(100)
    if (去消费) {
        break;
    }
    click("立即领取")
    var img = captureScreen();
 找图(图集,img)
  
   var img = captureScreen();
    //浇水按钮
   var p = images.findMultiColors(img, "#eaff83",[[9,-16,"#2067f3"],[-13,16,"#2067f3"],[-20,-29,"#2dcdff"],[19,30,"#29ccff"]]);//蓝水湖
    if (p) {
        log("蓝色浇水按钮");
        click(p.x, p.y)
    }
    p=images.findMultiColors(img, "#ff6000",[[10,-13,"#fae621"],[-22,-11,"#fae621"],[-56,3,"#ee7800"],[-15,42,"#ffad54"],[-67,98,"#0f9fb2"]]);//金水湖
     if(p){
        log("金色浇水按钮");
        click(p.x, p.y)
    }

 /*
  //开心收下
 找色("#fdb522",[[-2,-13,"#ffffff"],[0,14,"#feebc9"],[-53,-1,"#ffffff"],[82,-3,"#ffffff"],[47,-6,"#fdba25"],[38,7,"#fdb01e"],[1,-11,"#ffffff"]],"开心收下");
 
  
   
    //安装领取
    找色( "#fffffd",[[-46,3,"#fffff6"],[77,0,"#ffffff"],[58,-5,"#fcb922"],[9,2,"#f9b428"],[0,-326,"#58e3e0"],[38,-442,"#005dc7"],[246,-279,"#fff0db"]],"安装领取");
    
    
    //第二个安装领取
   找色("#fdb11f",[[-26,1,"#ffffff"],[-76,0,"#ffffff"],[60,-5,"#ffffff"],[132,-7,"#fdb622"],[-171,-1,"#fdb11f"],[-31,-38,"#fecd32"],[39,-380,"#ffffff"],[-33,-347,"#4dbaf4"]],"第二个安装领取");
    
    //点击领取100g水滴+2花瓣
    找色( "#ffffff", [[-14, 1, "#ffffff"], [-6, 1, "#fdb723"], [-136, 0, "#ffffff"], [160, -10, "#ffffff"], [28, -306, "#ffffff"], [-206, -555, "#fcd604"], [-48, -576, "#668c09"]],"点击领取100g水滴+2花瓣");
   
    //恭喜您获得大水壶奖励 去浇水
    找色("#ffffff", [[-50, -4, "#ffffff"], [43, 5, "#ffffff"], [-155, 12, "#fdae1d"], [188, 19, "#fca91a"], [-3, -34, "#ffd034"], [12, 45, "#fca01b"], [47, -552, "#ff6000"], [82, -530, "#fae621"]],"下应用领水滴去浇水");
  
    //下应用领水滴去浇水
    找色("#ffffff",[[-51,-5,"#ffffff"],[39,-1,"#ffffff"],[-129,8,"#fdb01e"],[177,25,"#fca518"],[2,-482,"#56c3f7"],[44,-549,"#feffff"]],"下应用领水滴去浇水");
   
    //安装领取
    找色( "#fdc13f",[[-8,10,"#fdb01e"],[-20,-5,"#fdbc26"],[-38,-5,"#ffffff"],[-58,-30,"#fece33"],[-32,-397,"#50bdf4"],[18,-481,"#ffffff"]],"安装领取");
    
    //关闭下应用去浇水
    找色("#ffffff",[[-10,618,"#005fc9"],[-61,691,"#7aeee1"],[-51,1154,"#ffffff"],[-1,1160,"#ffffff"],[74,1173,"#fdb01e"],[15,1167,"#fdb421"],[-34,1157,"#fdbc26"]],"关闭下应用去浇水");
    
    //知道了
  找色("#fdb522",[[-30,-14,"#ffffff"],[26,-15,"#ffffff"],[63,-3,"#ffffff"],[111,11,"#fdad1c"],[-132,11,"#fdad1c"],[9,-384,"#ffcb35"],[-1,-291,"#ff8417"],[212,-268,"#ffeac5"]],"知道了");
   
    //关闭下应用去浇水2
   找色( "#ffffff",[[-4,503,"#54cbfa"],[40,595,"#feffff"],[-76,688,"#2196ec"],[-51,1165,"#ffffff"],[-28,1159,"#fdb924"],[-2,1169,"#fdb21f"],[20,1168,"#fdb320"],[4,1178,"#ffffff"]],"关闭下应用去浇水2");
  */

}
threads.shutDownAll()
卸载app1()
function 找色( 颜色, 各坐标颜色, 日志) {
    //var img = captureScreen();
    var p = images.findMultiColors(img, 颜色, 各坐标颜色)
    if (p) {
        sleep(1000)
        console.log(日志);
        click(p.x, p.y);
        sleep(1000)
    }
}

function 区域找色(img, 颜色, 各坐标颜色, 区域坐标, 日志) {
    //var img = captureScreen();
    var p = images.findMultiColors(img, 颜色, 各坐标颜色, {
        region: 区域坐标
    })
    if (p) {
        sleep(1000)
        console.log(日志);
        click(p.x, p.y);
        sleep(1000)
    }
}

function 卸载app1() {
    //sleep(30000);
    log("开始卸载");
    var pm = context.getPackageManager()
    var appList = pm.getInstalledApplications(0)

    for (let i = 0; i < appList.size(); i++) {
        var app_ = appList.get(i)
        var appInfo = {
            appName: app_.loadLabel(pm),
            packageName: app_.packageName,
            isSystemApp: app_.isSystemApp(),
            lastUpdateTime: pm.getPackageInfo(app_.packageName, 0).lastUpdateTime
        }
        if (appInfo.lastUpdateTime > time) {
            console.log(appInfo.appName + "卸载中");
            app.uninstall(appInfo.packageName);
            sleep(1000)
            while (!click("卸载"));
        }
    }



    sleep(15000);
    log("卸载完成");

}

function 找图(图集,截图){
for(var i=0;i<图集.length;i++){
 
var p = findImage(截图,图集[i]);
if(p){
    log(p)
   var x=p.x*1+图集[i].getWidth()/2
   var y=p.y*1+图集[i].getWidth()/2
   log(图集[i].getWidth()/2,图集[i].getWidth()/2)
   click(x,y)
}

}
sleep(500)

}